//
//  RGMessageFunsCell.m
//  RedGrass
//
//  Created by wuyine on 2018/12/6.
//  Copyright © 2018年 hongcaosp. All rights reserved.
//

#import "RGMessageFunsCell.h"

@interface RGMessageFunsCell()
@property (nonatomic,strong) UIButton *followBtn;
@end

@implementation RGMessageFunsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self initChildUI];
        [self addChildMasonry];
        self.userIcon.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(enterPersonalPage:)];
        [self.userIcon addGestureRecognizer:tap];
    }
    return self;
}

- (void)enterPersonalPage:(UITapGestureRecognizer *)recong {
    if (self.enterPersonalPageBlock) {
        self.enterPersonalPageBlock();
    }
}

- (void)setModel:(RGMessageContactModel *)model {
    [self.userIcon setImageWithURL:[NSURL URLWithString:model.image] placeholder:IMAGE_NAMED(@"头像1")];
    self.userName.text = model.nickname;
    self.contentLabel.text = @"关注了你";
    self.dateLabel.text = [NSDate dateWithTimeStamp:[NSString stringWithFormat:@"%@",model.createTime] withFormatter:@"MM-dd HH:mm"];
    self.followBtn.selected = model.meFollowmTa;
    if (model.meFollowmTa == YES) {
        self.followBtn.backgroundColor = UICOLOR_WITH_RGBINT(0x716d7f);
    }else {
        self.followBtn.backgroundColor = UICOLOR_WITH_RGBINT(0xf73152);
    }
}

- (void)setFindFriendModel:(RGMessageContactModel *)findFriendModel {
    _findFriendModel = findFriendModel;
    [self.userIcon setImageWithURL:[NSURL URLWithString:findFriendModel.image] placeholder:IMAGE_NAMED(@"头像1")];
    self.userName.text = findFriendModel.nickname;
//    self.contentLabel.text = @"TA在关注你哦";
//    self.dateLabel.text = [NSString stringWithFormat:@"%d作品 %d粉丝",findFriendModel.worksCount,findFriendModel.fansCounts];
    self.followBtn.selected = findFriendModel.meFollowmTa;
    if (findFriendModel.meFollowmTa == YES) {
        self.followBtn.backgroundColor = UICOLOR_WITH_RGBINT(0x716d7f);
        self.followBtn.selected = YES;
    }else {
        self.followBtn.backgroundColor = UICOLOR_WITH_RGBINT(0xf73152);
        self.followBtn.selected = NO;
    }
}

-(void)updateUIStyleWhenShowContactUser{
    self.contentLabel.hidden = YES;
    self.dateLabel.hidden = YES;
    [self.userName mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.userIcon.mas_trailing).offset(10);
        make.centerY.mas_equalTo(self.contentView).mas_offset(0);
    }];
}

-(void) initChildUI{
    [self.contentView addSubview:self.followBtn];
}

-(void) addChildMasonry {
    [_followBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(-15);
        make.size.mas_equalTo(CGSizeMake(80, 30));
        make.centerY.mas_equalTo(0);
    }];
}

- (void)addOrCancel:(UIButton *)btn {
    if (self.addOrCancelBlock) {
        self.addOrCancelBlock(btn);
    }
}

- (UIButton *)followBtn {
    if (!_followBtn) {
        _followBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_followBtn setTitle:@"关注" forState:UIControlStateNormal];
        [_followBtn setTitle:@"互相关注" forState:UIControlStateSelected];
        self.followBtn.backgroundColor = UICOLOR_WITH_RGBINT(0xf73152);
//        [_followBtn setBackgroundImage:IMAGE_NAMED(@"矩形6") forState:UIControlStateSelected];
//        [_followBtn setBackgroundImage:IMAGE_NAMED(@"btn_normal") forState:UIControlStateNormal];
        _followBtn.titleLabel.font = FONT(customFontName, 13);
        [_followBtn addTarget:self action:@selector(addOrCancel:) forControlEvents:UIControlEventTouchUpInside];
        _followBtn.layer.cornerRadius = 4;
        _followBtn.layer.masksToBounds = YES;
    }
    return _followBtn;
}

@end
